package com.yanghs.shiro.filter;

import org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author yanghs
 * @Description:重写权限控制filter让其支持url权限控制
 * @date 2018/3/5 14:06
 */
public class UrlAuthorizationFilter extends PermissionsAuthorizationFilter {
    @Override
    public boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws IOException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        String path =  httpServletRequest.getContextPath();
        String uri = httpServletRequest.getRequestURI();
        uri =  uri.substring(path.length(),uri.length());

        String[] perms = new String[1];
        perms[0] = uri;
        return super.isAccessAllowed(request, response, perms);
    }
}
